<!DOCTYPE HTML>
<html lang="en">
<head>
<title>#UseHook - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The #UseHook directive forces the use of the hook to implement all or some keyboard hotkeys." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>#UseHook</h1>

<p>Forces the use of the  hook to implement all or some keyboard <a href="../Hotkeys.htm">hotkeys</a>.</p>

<pre class="Syntax"><span class="func">#UseHook</span> <span class="optional">OnOff</span></pre>
<h2>Parameters</h2>
<dl>

  <dt>OnOff</dt>
  <dd>
    <p>Specify one of the following words (if omitted, it defaults to On):</p>
    <p><strong>On</strong>: The <a href="_InstallKeybdHook.htm">keyboard hook</a> will be used to implement all keyboard hotkeys between here and the next <code>#UseHook OFF</code>  (if any).</p>
    <p><strong>Off</strong>: Hotkeys will be implemented using the default method (RegisterHotkey() if possible; otherwise, the keyboard hook).</p>
  </dd>

</dl>

<h2>Remarks</h2>
<p>Normally, the windows API function RegisterHotkey() is used to implement a keyboard hotkey whenever possible. However, the responsiveness of hotkeys might be better under some conditions if the <a href="_InstallKeybdHook.htm">keyboard hook</a> is used instead.</p>
<p>Turning this directive ON is equivalent to using the <a href="../Hotkeys.htm#prefixdollar">$ prefix</a> in the definition of each affected hotkey.</p>
<p>As with all # directives -- which are processed only once when the script is launched --  <code>#UseHook</code> should not be positioned in the script as though it were a command (that is, it is not necessary to have it contained within a subroutine). Instead, position it immediately before the first hotkey label you wish to have affected by it.</p>
<p>By default, hotkeys that use the <a href="_InstallKeybdHook.htm">keyboard hook</a> cannot be triggered by means of the <a href="Send.htm">Send</a> command. Similarly, mouse hotkeys cannot be triggered by commands such as <a href="Click.htm">Click</a> because all mouse hotkeys use the <a href="_InstallMouseHook.htm">mouse hook</a>. One workaround is to use <a href="Gosub.htm">Gosub</a> to jump directly to the hotkey's subroutine. For example: <code>Gosub #LButton</code>.</p>
<p><span class="ver">[v1.1.06+]:</span> <a href="_InputLevel.htm">#InputLevel</a> and <a href="SendLevel.htm">SendLevel</a> provide additional control over which hotkeys and hotstrings are triggered by the Send command.</p>
<p>If this directive does not appear in the script at all, it will behave as though set to OFF.</p>

<h2>Related</h2>
<p><a href="_InstallKeybdHook.htm">#InstallKeybdHook</a>, <a href="_InstallMouseHook.htm">#InstallMouseHook</a>, <a href="ListHotkeys.htm">ListHotkeys</a>, <a href="_InputLevel.htm">#InputLevel</a></p>
<h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>#UseHook  <em>; Force the use of the hook for hotkeys after this point.</em>
#x::MsgBox, This hotkey will be implemented with the hook.
#y::MsgBox, And this one too.
#UseHook off
#z::MsgBox, But not this one.</pre>
</div>

</body>
</html>
